package com.itibo.models;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

public class CSVDocument extends Document {
	Scanner scaner;

    public CSVDocument(){
        body=new StringBuilder();
    }

	public CSVDocument(String file) throws FileNotFoundException {
		super(file);
		scaner = new Scanner(new File(file));
	}

    public CSVDocument(byte[] bytes) throws FileNotFoundException {
        super(bytes);
        String str = null;
        try {
            str = new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        scaner = new Scanner(str);
    }

	public String[] readObject() {
		if (scaner.hasNext()) {
			return scaner.nextLine().split(",");
		}
		return null;
	}
    public void writeObject(String[] s1){
        String currentSong=s1[0]+","+s1[1]+","+s1[2]+","+s1[3];
        body.append(currentSong).append('\n');

    }

}
